R: How to Draw Circles in Plots (With Examples)

您所在的位置:网站首页 dataframe plot scatter R: How to Draw Circles in Plots (With Examples)

R: How to Draw Circles in Plots (With Examples)

#R: How to Draw Circles in Plots (With Examples)| 来源: 网络整理| 查看: 265

You can use the following methods to draw a circle in a plot in R:

Method 1: Draw Circle Using Base R

library(plotrix) #create scatter plot plot(x, y) #add circle at specific (x, y) coordinates with specific radius draw.circle(x=3, y=8, radius=.5)

Method 2: Draw Circle Using ggplot2

library(ggplot2) library(ggforce) #create scatter plot with circle at specific location with specific radius ggplot(data = df, aes(x, y)) + geom_point() + geom_circle(aes(x0=3, y0=8, r=1), inherit.aes=FALSE) + coord_fixed()

The following examples shows how to use each method in practice.

Example 1: Draw Circle Using Base R

To draw a circle on a plot in base R, you need to first install and load the plotrix package:

install.packages('plotrix') library(plotrix)

Next, we can use the draw.circle() function from the plotrix package to add a circle to a scatter plot in base R:

#create data frame df


【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3